package com.example.coco.Controller;

import com.example.coco.model.Cusumer;
import com.example.coco.res.CusumerMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import java.util.Map;

@RestController

public class Reg {
    @Autowired
    CusumerMapper cusumerMapper;
    @RequestMapping("/register")
    @ResponseBody
    public Object addCusumer(@RequestParam Map<String, Object> params)
    {
        String userid = (String) params.get("userid");
        String userpassword = (String) params.get("userpassword");
        String password = (String) params.get("password2");

//        cusumer.setUserid(userid);
//        cusumer.setUserpassword(userpassword);
//        cusumerMapper.insertCusumer(cusumer);

        String a = cusumerMapper.findlog(userid);
        if (a != null && !a.equals("") || password.equals("") || password.equals("null")){
            return new ModelAndView("regError");
        }else{
            Cusumer cusumer = new Cusumer();
            cusumer.setUserid(userid);
            cusumer.setUserpassword(userpassword);
            cusumerMapper.insertCusumer(cusumer);
            return new ModelAndView("login");
        }
//        return new ModelAndView("login");

    }
}
